import axios from 'axios';
import {
  Loading
} from 'element-ui';

// const getBaseUrl = 'http://121.40.41.188:8080/car/api5'

const getBaseUrl = 'http://www.bjdd301.cn:80/car/api5'


const baseGet = (url, data, callback) => {
  axios.request({
    url: url,
    method: 'get',
    params: data
  }).then(function (res) {
    callback(res)
  }).catch(function (error) {
    var result = {
      error: true
    }
    callback(result)
  })
}

export const getVinData = (url, data, _self, callback, target) => {

  var curUrl = getBaseUrl + '?url=' + url
  let loading = getLoading(target);
  baseGet(curUrl, data, (res) => {
    setTimeout(() => {
      loading.close();
    }, 300)
    if (res.data.data.error) {
      toast && _self.$notify.error("操作失败,请联系管理员");
    } else {
      callback(eval("("+res.data.data+")") );
    }
  })
}

var getLoading = (target) => {
  return Loading.service({
    target: target ? target : document.body,
    fullscreen: false,
    text: "拼命加载中~"
  });
}